<template>
    <!-- 弹出层 -->
    <div class="modal fade" id="mergeDeptModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                    <h4 class="modal-title" id="myModalLabel">合并部门</h4>
                </div>
                <div class="modal-body">
                    <div class="form-horizontal">
                        <div class="form-group">
                            <label  class="col-sm-4 control-label">合并部门<label style="color: red;">*</label>：</label>
                            <div class="col-sm-8">
                                <input type="text" readonly  name="departmentName" v-model="mergeDeptModal.name" class="form-control">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="" class="col-sm-4 control-label">接受部门<label style="color: red;">*</label>：</label>
                            <div class="col-sm-8">
                                <ul id="acceptTree" class="ztree"></ul>
                            </div>
                        </div>

                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" v-on:click="mergeDept"  class="btn checkedBtn">确定</button>
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                </div>
            </div>
        </div>
    </div>
</template>
<style>
    body{
    }
</style>
<script>
    export default{
        props: ["mergeDeptModal"],
        data(){
            return{

            }
        },
        mounted: function() {
            this.loadOrgTreeData();
        },
        activated:function(){
            this.loadOrgTreeData();
        },
        methods:{
            loadOrgTreeData: function() {
                //ztree基础属性设置
                var setting = {
                    data: {
                        simpleData: {
                            enable: true
                        }
                    }
                };
                var body= {};
                body.params = {}
                var _self = this;
                var url = _self.utilHelper.apiUrl + "/api/getDeptTree";
                _self.$http.post(url, body).then((response) => {
                var data = response.body;
                var deptData = data.resData;
//                var result = data.result;
                $.fn.zTree.init($("#acceptTree"), setting, deptData);
                }, (response) => {

                });
            },
            mergeDept:function(){
                var _self = this;
                var treeObj = $.fn.zTree.getZTreeObj("acceptTree");
                var nodes = treeObj.getSelectedNodes();

                if(this.mergeDeptModal.id == nodes[0].id){
                    layer.msg("不能与本部门合并");
                    return;
                }
                //准备数据
                var body= {}
                body.params = {
                    deptId:this.mergeDeptModal.id,
                    deptLevel:this.mergeDeptModal.level,
                    acceptId:nodes[0].id,
                    acceptLevel:nodes[0].level

                };

                var url = _self.utilHelper.apiUrl + "/api/mergeDept";
                _self.$http.post(url, body).then((response) => {
					var data = response.body;
					if(data.result == '1'){
						layer.msg("操作成功");
						$("#mergeDeptModal").modal('hide');
						_self.$emit('saveOrgListener');
					}else{
						layer.msg(data.resData.resultMsg);
					}
				}, (response) => {

                });
            }
        }

    }
</script>
